<template>
  <div style="width: 1000px">
    <el-table border class="inputcolumn" :data="selectedDataCopy" style="width: 1000px">

      <el-table-column label="商品类型" align="center" prop="shopTypeStr" />
                <el-table-column label="商品名称" align="center" prop="shopName" width="240px">
                </el-table-column>
                <el-table-column label="活动类型" align="center" prop="activityTypeStr" />
                <el-table-column label="活动时间" align="center" prop="time" width="260px" >
                    <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.startTime, '{y}年{m}月{d}日') }}-
                            {{ parseTime(scope.row.endTime, '{y}年{m}月{d}日') }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="库存" align="center" prop="activityStock" />
                <el-table-column label="销量" align="center" prop="activitySaleAmount" />


      <el-table-column align="center" prop="receiveNumber" label="操作" v-if="canDelete"  fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleDeleteser(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page-sizes="pageSizess" :page.sync="pageNum" :limit.sync="pageSize"
      @pagination="getList" />



  </div>
</template>
<script>
export default {
  props: {
    selectedData: {
      type: Array,
      default: function () {
        return []
      }
    },
    canDelete: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      selectedDataCopy: [],
      total: this.selectedData.length,
      pageSizess: [5, 10, 15, 20, 25, 30, 50],
      pageNum: 1,
      pageSize: 5,

    }
  },

  created() {
    if (this.total > 0) {
      this.getList();
    }
  },
  methods: {
    getList() {
      this.selectedDataCopy = [];
      let startNum = (this.pageNum - 1) * this.pageSize;
      let endNum = this.pageNum * this.pageSize;
      /*if($this.pageNum == 1){
        num =  $this.pageNum * $this.pageSize;
      }*/
      this.total = this.selectedData.length

      this.selectedData.forEach((data, index) => {
        if (index >= startNum && index < endNum) {
          this.selectedDataCopy.push(data);
        }
      })
      if (this.selectedDataCopy.length == 0) {
        if (this.pageNum > 1) {
          this.pageNum = this.pageNum - 1
          this.getList()
        }
      }
 
      console.log(this.selectedData)
      console.log(this.selectedDataCopy)
    },
    handleDeleteser(val, row) {
      // 模态框删除按钮
      this.$confirm("是否确认删除本条数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info",
      }).then(() => {
        let index = null
        this.selectedData.forEach((item, idx) => {
          if (item.activityId == row.activityId) {
            index = idx
          }
        })
        this.selectedData.splice(index, 1);
        //数据回传
         this.$emit('tabRespon', this.selectedData)
        //this.getList();
      });
    },
  },
};
</script>
